package com.hhl.test01.service;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hhl.test01.dao.UserMapper01;
import com.hhl.test02.dao.UserMapper02;
import com.hhl.test02.service.UserServiceTest02;

@Service
public class UserServiceTest01 {
	@Autowired
	UserMapper01 userMapper01;
	@Autowired
	UserMapper02 userMapper02;
	@Autowired
	UserServiceTest02 userServiceTest02;
	@Autowired
	UserServiceTest01 userServiceTest01;
	//回滚当前记录
	@Transactional
	public String addMybatisUser01(String name,Integer age){
		userMapper01.insert(name, age);
		userMapper02.insert(name, age);//直接调用dao层，第一种可以回滚，第二种不能
		/**
		 * 此时用了Atomikos,调用dao层，则2种都会回滚
		 */
//		userServiceTest02.addMybatisUser02(name, age);//调用service层，前后两种可以回滚
		
		int i = 1/0;
		return "success";
	}
}
